/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-07 16:47:40
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-27 10:35:40
 * @FilePath: /webServer/src/model/user/user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  Column,
  Entity,
  JoinTable,
  ManyToMany,
  ManyToOne,
  OneToMany,
} from 'typeorm';
import { DBColumns } from '../';
import {
  DepartmentSchema,
  ProcessFilesSchema,
  RoleSchema,
  UserSchema,
} from '../../schema';
import { Role } from '../role/role';
import { Department } from '../department/department';
import { ProcessFiles } from '../process_files/process_files';

@Entity('user')
export class User extends DBColumns implements UserSchema {
  @Column({ type: 'timestamp', nullable: true })
  lastLogoutTime?: Date;
  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '姓名',
  })
  userName: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    default: null,
    comment: '邮箱',
  })
  email?: string;

  @Column({
    type: 'varchar',
    length: 18,
    nullable: false,
    default: null,
    comment: '身份证号',
  })
  idCardNo: string;

  @Column({
    type: 'varchar',
    length: 11,
    nullable: false,
    default: null,
    comment: '手机号',
  })
  mobile: string;
  @Column({
    type: 'varchar',
    length: 255,
    nullable: false,
    default: null,
    comment: '头像',
  })
  avatar?: string;

  @Column({
    type: 'varchar',
    length: 36,
    nullable: false,
    default: null,
    comment: '密码',
    select: false,
  })
  password: string;

  @ManyToMany(() => Role, role => role.user)
  @JoinTable({ name: 'user_role' })
  role?: RoleSchema[];

  @ManyToOne(() => Department, dept => dept.user)
  dept?: DepartmentSchema;

  @OneToMany(() => ProcessFiles, process_files => process_files.user)
  mergePdfs: ProcessFilesSchema[];
}
